{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Laminar pipe flow - Hagen–Poiseuille solution"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this tutorial we use icoFoam to compute a laminar pipe flow, then we compare the numerical solution with the analytical solution. <br>\n",
    "\n",
    "You will find the instructions of how to run this case in the file README.FIRST. <br>\n",
    "\n",
    "By the way, to plot the numerical solution you need to use the utility sample to get the solution at the end of the pipe."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'np' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[43mnp\u001b[49m\u001b[38;5;241m.\u001b[39mloadtxt(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m../postProcessing/sampleDict/20/s2_U.xy\u001b[39m\u001b[38;5;124m'\u001b[39m, skiprows\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'np' is not defined"
     ]
    }
   ],
   "source": [
    "data = np.loadtxt('../postProcessing/sampleDict/20/s2_U.xy', skiprows=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "fig = plt.figure(figsize=(12,8))\n",
    "\n",
    "data=np.loadtxt('../postProcessing/sampleDict/20/s2_U.xy', skiprows=0)\n",
    "\n",
    "plt.plot(data[:,0],data[:,1],'o',label='icoFoam')\n",
    "\n",
    "vmax = max(data[:,1])\n",
    "rmax = 0.5\n",
    "\n",
    "x = np.linspace(-1*rmax, rmax, 100)\n",
    "sol = vmax*(1 - x**2/rmax**2)\n",
    "\n",
    "plt.plot(x,sol,'-',label='Analytical solution')\n",
    "\n",
    "plt.legend()\n",
    "plt.grid()\n",
    "plt.xlabel('Radius',fontsize=15)\n",
    "plt.ylabel('$V_{axial}$',fontsize=15)\n",
    "\n",
    "\n",
    "\n",
    "#To save a figure\n",
    "#plt.savefig('test.png', format='png', dpi=300)\n",
    "#plt.savefig('test.pdf', format='pdf', dpi=300)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
